When we use adb push $file /mnt/sdcard on Android 11 devices, we will encounter adb: error: stat failed when trying to push to /mnt/sdcard/: Permission denied error message. This article will introduce how to solve the problem and share related thoughts.
Change the path from /mnt/sdcard to /sdcard, which means adb push $file /sdcard
Regarding these two symlinks, they have to be traced back to the period before and after Android 4.0, and there is less information available for research. Before Android 4.0, the /mnt/sdcard should be used. After the system is upgraded, to be compatible with the old version, this Pointing becomes symlink.
On systems below 6.0, there is also /storage/sdcard/legacy, and on 6.0 and above, it become /storage/self/primary.
Now, I found an Android 6.0.1 mobile phone, let’s take a look at the symlinks left over from various historical versions, and what they look like in the shell.
$ adb shell ls -al /mnt | grep sdcard
lrwxrwxrwx root root 2021-02-16 11:17 sdcard -> /sdcard
As you can see, /mnt/sdcard points to /sdcard
$ adb shell ls -al / | grep sdcard
lrwxrwxrwx root root 2021-02-16 11:17 sdcard -> /storage/self/primary
And /sdcard points to /storage/self/primary
$ adb shell ls -al /storage/self/
lrwxrwxrwx root root 2021-02-16 11:17 primary -> /mnt/user/0/primary
/storage/self/primary points to /mnt/user/0/primary
$ adb shell ls -al /mnt/user/0/primary
lrwxrwxrwx root root 2021-02-16 11:17 primary -> /storage/emulated/0
Continue to trace back, /mnt/user/0/primary points to /storage/emulated/0, which is the path of the SD card that we are familiar with.
As can be seen from the above, /mnt/sdcard is a symlink, which can be viewed on Android 11 devices through ls
$ adb shell ls -al /mnt | grep sdcard
l????????? ? ? ? ? ? sdcard -> ?
As you can see, although the soft link still exists, it can no longer be accessed normally, that is, the error of Permission denied shown in the title will be thrown.
For comparison, use the same command to view on the Android 6.0.1 device
$ adb shell ls -al /mnt | grep sdcard
lrwxrwxrwx root root 2021-02-16 11:17 sdcard -> /sdcard
This is the symlink that can be used normally.
Nowadays, very few apps support Android versions below 5.0, and each major version of the Android system is updated. In addition to the compatibility issues of the APP itself, it takes time to pay attention to compatibility issues in the same ecosystem.
/mnt stands for the mount , you will find files there when you mount your filesystem or devices.
If you have anything you'd like to discuss, any ideas you want to bounce around, please send me a message.